<%@ page language="java" import="java.util.*,shop.dao.*,shop.entity.*"  pageEncoding="utf-8"%>
<%	OrdersDao ordersdao=new OrdersDao();
    Orders  orders=new Orders();
	ProductDao ProductDao=new ProductDao();
	
	String order_number=(String)session.getAttribute("order_number");
	String pay_email=(String) session.getAttribute("pay_email");
	String pay_fangshi=(String) session.getAttribute("pay_fangshi");
    String sum = request.getParameter("sum");
	String o_time=(String) session.getAttribute("o_time");
	String username=(String)session.getAttribute("username");
	String order_userId=(String)session.getAttribute("userID");
	
	orders.setOrder_id(order_number);
	orders.setOrder_email(pay_email);
	orders.setOrder_payment(pay_fangshi);
    orders.setOrder_sum(Float.parseFloat(sum));
	orders.setOrder_time(o_time);
	orders.setOrder_user(username);
	orders.setOrder_userId(order_userId);
	
	int temp=ordersdao.insertOrders(orders);
	if(temp!=0)
	{
			Vector cart=(Vector)session.getAttribute("cart");

	        for(int i=0;i<cart.size();i++)
         	{
	     	CartBean goodsitem=(CartBean)cart.elementAt(i);
	     	
		    String price=String.valueOf(goodsitem.p_price);
		    String number=String.valueOf(goodsitem.p_number);

		    int temp2=ordersdao.insertOrderDetails(order_number,goodsitem.p_id,price,number);
		    
		    int temp3=ProductDao.updateProductPurchase(goodsitem.p_id,goodsitem.p_number);
		    
		    out.print(goodsitem.p_number);
		    if(temp2!=0 && temp3!=0)
		    {
                
		    }
		    else
		    {
		    out.println("<script language='javascript'>alert('订单发送失败!');window.location.href='../index.jsp';</script>");
		    }
	        }
	    	cart.removeAllElements();	
	        out.println("<script language='javascript'>alert('订单发送成功!');window.location.href='../index.jsp';</script>");
	}
	 else
		    {
		    out.println("<script language='javascript'>alert('订单发送失败11!');window.location.href='../index.jsp';</script>");
		    }
 %>
